//
//  LayoutUtils.m
//  MasonryExample
//
//  Created by 山刘 on 2020/6/10.
//  Copyright © 2020 山刘. All rights reserved.
//

#import "LayoutUtils.h"

@implementation LayoutUtils
+ (UILabel *)fixedLabelWithText:(NSString *)text {
    
    UILabel *label = [UILabel new];
    label.numberOfLines = 0;
    label.lineBreakMode = NSLineBreakByTruncatingTail;
    label.translatesAutoresizingMaskIntoConstraints = NO;
    label.backgroundColor = [self randomColor];
    label.textAlignment = NSTextAlignmentCenter;
    label.text = text;
    return label;
    
}

+(UIView*)createView {
    
    UIView *view = UIView.new;
    view.backgroundColor = [self randomColor];
    view.layer.borderColor = UIColor.blackColor.CGColor;
    view.layer.borderWidth = 2;
    return view;
}

+(UIButton *)createButtonWithTitle:(NSString*)title target:(id)target selector:(SEL)selector {
    UIButton *button = [[UIButton alloc] init];
    [button setTitle:title forState:UIControlStateNormal];
    button.backgroundColor = [self randomColor];
    [button addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
    return button;
}

+(UIScrollView*)creatUIScrollView {
    UIScrollView *scrollView = [[UIScrollView alloc] init];
    scrollView.backgroundColor = [self randomColor];
    scrollView.pagingEnabled = YES;
    return scrollView;
}

+ (UIColor *)randomColor {
    
    CGFloat hue = ( arc4random() % 256 / 256.0 );  //  0.0 to 1.0
    CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5;  //  0.5 to 1.0, away from white
    CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5;  //  0.5 to 1.0, away from black
    return [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];
    
}

+(UIStackView*)creatStackView {
    UIStackView *stackView = [[UIStackView alloc] init];
    return stackView;
}
@end
